<?php

class spDate extends spDiv
{
	private $input_text;

	public function __construct( $data=null )
	{
		parent::__construct( $data );
		parent::setClass( "spDate" );
		
		$date_name = isset($data["date_name"])?$data["date_name"]:"";
		$date_value = isset($data["date_value"])?$data["date_value"]:"";
		
		$this->input_text = new spInputText( array( "class"=>"spDateInput", "name"=>$date_name, "value"=>$date_value) );
		$this->input_text->addAttr( "readonly", "true" );
		parent::addChild( $this->input_text );
	}	
	
	public function addData( $key, $value )
	{
		$data = parent::addData( $key, $value );	
		
		if ( isset($data["readonly"]) &&  $data["readonly"]=="readonly" )
		{
			$this->input_text->setClass( "spDateInput_readonly" );
		}
	}

	public function setElementDataString( $s )
	{
		parent::setElementDataString( $s );	
		
		$this->input_text->addAttr ( "value", $s );
	}
	
	public function updateFromRequest()
	{
		parent::updateFromRequest();
		
		// convience variables
		$data = parent::getData();
		$r = $_REQUEST;	

		$value = $r[$data["date_name"]];		
			
		$this->setElementDataString( $value );
	}
}

?>